package bdu;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import bdu.test.RobotTestBed;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;

/**
 * Illustrates JUnit testing of Robocode robots.
 * This test verifies that Scavenger only fires at stationary targets
 * @author Bao Huy Ung
 *
 */
public class TestScavengerFireStationary extends RobotTestBed {

  double lastXCoord;
  double lastYCoord;
  boolean fireCheck;
  
  /**
   * Specifies that SittingDuck and Scavenger are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,bdu.Scavenger";
  }
  
  /**
   * This test runs for 10 rounds.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
  
  /**
   * Test to see if there has been a bullet fired through tracking of gun heat
   * test looks to see if the enemy robot is moving if it is not it will check if
   * there has been a bullet fired at the end of a turn.
   * 
   * @param event Ending of a turn for a robot
   */
  @Override 
  public void onTurnEnded(TurnEndedEvent event) {
    // Get and store information on the enemies robot location.
    IRobotSnapshot enemy = event.getTurnSnapshot().getRobots()[0];
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    double yCoord = enemy.getY();
    double xCoord = enemy.getX();
   
    // Since the last turn if no movement has been detected, check for fire from scavenger
    if (lastXCoord == xCoord || lastYCoord == yCoord && robot.getGunHeat() > 0) {
      //if the gun has been fired, there will be a gun heat cool down time
        fireCheck = true;
    }
    
    // Update the enemies last known coordinate.
    lastXCoord = xCoord;
    lastYCoord = yCoord;
  }
  
  /**
   * The actual test, which asserts that there was fire on the stationary target.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Fired Upon Stationary Target", fireCheck);
  }
}
